﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeneralClasses;

namespace Interface
{
    public partial class frmSchedulerProgress : Form
    {
        Form opener;
        Timer timer;
        DateTime startTime;
        DateTime endTime;

        public frmSchedulerProgress(Form Opener, DateTime EndTime)
        {
            opener = Opener;
            InitializeComponent();
            timer = new Timer();
            timer.Interval = 1000;
            timer.Start();
            timer.Tick += new EventHandler(timer_Tick);
            startTime = DateTime.Now;
            endTime = EndTime;
        }

        void timer_Tick(object sender, EventArgs e)
        {
            prgCompleted.Value = (int)((DateTime.Now.Ticks - startTime.Ticks) / (endTime.Ticks - startTime.Ticks));

            txtTimeLeft.Text = Convert.ToString((endTime - DateTime.Now));
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SchedulerProgress_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (opener != null)
            {
                opener.Show();
            }
        }

        private void btnEndSchedulingEarly_Click(object sender, EventArgs e)
        {
            //tell scheudler to end eairly
            List<Schedule> schedules = new List<Schedule>(); //scheduler.endEairly();
            frmChooseSchedule chooseSchedule = new frmChooseSchedule(schedules, opener);
            opener = null;
            this.Close();
            chooseSchedule.Show();
        }

        //need to get scheduler to call this
        void schedulerFinished(List<Schedule> schedules)
        {
            frmChooseSchedule chooseSchedule = new frmChooseSchedule(schedules, opener);
            opener = null;
            this.Close();
            chooseSchedule.Show();
        }
    }
}
